package com.kitty.game.fight.facade;

import com.kitty.game.difushidao.service.DiFuShiDaoService;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.equip.service.FabaoService;
import com.kitty.game.i18n.I18nId;
import com.kitty.game.pet.model.Pet;
import com.kitty.common.model.Pos;
import com.kitty.game.pk.service.PkService;
import com.kitty.game.role.model.Role;
import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.game.config.MapBossPos;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.activity.service.shidao.ShiDaoHandler;
import com.kitty.game.enter.Position;
import com.kitty.game.enter.ReqMultiMoveTo;


import com.kitty.game.fight.message.ReqAutoFightInfo;
import com.kitty.game.fight.message.ReqAutoFightSetData;
import com.kitty.game.fight.message.ReqAutoFightSetVictim;
import com.kitty.game.fight.message.ReqCombatEndAnimate;
import com.kitty.game.fight.message.ReqFightDoAction;
import com.kitty.game.fight.message.ReqFightFlee;
import com.kitty.game.fight.message.ReqFightPK;
import com.kitty.game.fight.message.ReqOpenFightMsgDlg;
import com.kitty.game.fight.message.ReqSetFightMsg;
import com.kitty.game.fight.message.RespCombatCommandAccepted;
import com.kitty.game.fight.message.RespFightCommandInfo;
import com.kitty.game.fight.message.RespFightMsgDlg;
import com.kitty.game.fight.message.RespSyncMessage;
import com.kitty.game.fight.service.FightExecutorService;
import com.kitty.game.fight.service.FightService;
import com.kitty.game.fight.util.FightAction;
import com.kitty.game.fight.util.FightMessageUtil;
import com.kitty.game.pet.PetDataPool;
import com.kitty.game.pet.PetType;
import com.kitty.game.pet.bean.PetObject;
import com.kitty.game.pet.message.ReqCatchPet;
import com.kitty.game.role.service.RoleService;
import com.kitty.game.team.model.Member;
import com.kitty.game.team.message.RespMsg;
import com.kitty.game.team.model.Team;
import com.kitty.game.team.service.TeamService;
import com.kitty.game.utils.AsktaoUtil;
import com.kitty.listener.EventDispatcher;
import com.kitty.listener.EventType;
import com.kitty.listener.annotation.EventHandler;
import com.kitty.listener.event.LogoutEvent;
import com.kitty.listener.event.MoveEvent;

import com.kitty.mina.annotation.RequestMapping;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.message.MessagePusher;
import lombok.extern.slf4j.Slf4j;
import org.apache.mina.core.session.IoSession;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.json.Json;
import org.nutz.lang.Strings;
import org.nutz.lang.util.NutMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.*;

@Controller
@Slf4j
public class FightController {


    @Autowired
    FightExecutorService fightExecutorService;

    @Autowired
    FightService fightService;

    @Autowired
    PkService pkService;

    /**
     * 设置自动技能
     */
    @RequestMapping
    public void setAutoSkill(IoSession session, ReqAutoFightSetData reqAutoFightSetData) {
        FightService fightService = SpringUtils.getBean(FightService.class);
        Role role = SessionUtils.getRoleBySession(session);
        int id = reqAutoFightSetData.getId();
        // 这里的autoSet必须用新申请的对象，否则会覆盖角色的技能。
        Map<String, Object> autoSet = new HashMap<>();
        autoSet.put("action", (int)reqAutoFightSetData.getAction());
        autoSet.put("type", (int)reqAutoFightSetData.getType());
        autoSet.put("skillId", reqAutoFightSetData.getSkillId());
        autoSet.put("list", reqAutoFightSetData.getList());
        autoSet.put("multi", (int)reqAutoFightSetData.getMulti_index());
        if (role.getRoleId() == id) {// 人物
            role.getExtendBox().setAutoFightSet(autoSet);
        } else {// 宠物
            Pet pet = SpringUtils.getPetService().getPetById(id, role);
            pet.setAutoFightSet(autoSet);
        }
        role.save();

        Fight fight = fightService.getFightByRoleId(role.getRoleId());
        if (fight != null) {
            fightExecutorService.addFightTask(fight, () -> {
                FightObject fightObject = fight.queryFightObject(id);
                if (fightObject != null) {
                    fightObject.setAutoFightType(reqAutoFightSetData.getType());
                    fightObject.setMultiIndex(reqAutoFightSetData.getMulti_index());
                    fightObject.setAutoSkillId(reqAutoFightSetData.getSkillId());
                    fightObject.setAction(reqAutoFightSetData.getAction());
                    fightObject.setSkillGroups(reqAutoFightSetData.getList());
                }
            });
        }
    }

    /**
     * 打开巡逻
     */
    @RequestMapping
    public void autoFightInfo(IoSession session, ReqAutoFightInfo reqAutoFightInfo) {
        Role role = SessionUtils.getRoleBySession(session);
        SpringUtils.getBean(RoleService.class).sendAutoSet(role);
    }

    /**
     * 玩家pk
     *
     * @param session
     * @param reqFightPK
     */
    @RequestMapping
    public void fightPK(IoSession session, ReqFightPK reqFightPK) {
        log.info("PK类型=={}", reqFightPK.getType());//普通切磋或者强P
        FightService fightService = SpringUtils.getBean(FightService.class);
        Role role = SessionUtils.getRoleBySession(session);
        Role pkRole = SpringUtils.getRoleService().getOnlinePlayer(reqFightPK.getRoleId());
        if (pkRole == null) {
            return ;
        }
        // 一定要先禁止同队伍中的PK
        TeamService teamService = (TeamService) SpringUtils.getBean(TeamService.class);
        Team team = teamService.getTeam(role.getRoleId());
        Team pkTeam = teamService.getTeam(pkRole.getRoleId());
        /**在监狱不能PK*/
        if (pkService.isInPrisonTime(role) || pkService.isInPrisonTime(pkRole)) {
            MessagePusher.notify2Player(role, I18nId.PMT_1125);
            return;
        }
//        if (true){
//            return;
//        }
        if (reqFightPK.getType() == 1) {
            /**强制PK*/
            SpringUtils.getBean(PkService.class).reqForcePK(role, pkRole);
            return;
        }

        Pos position = role.getPos();
        Pos pkPosition = pkRole.getPos();
        if (position.getMapId() != pkPosition.getMapId()) {
            return;
        }
        if (!SpringUtils.getBean(ShiDaoHandler.class).isCompetePK(role, pkRole)) {
            return;
        }
        if (!SpringUtils.getBean(DiFuShiDaoService.class).isCompetePK(role, pkRole)) {
            return;
        }
        Fight fightA = fightService.getFightByRoleId(role.getRoleId());
        Fight fightB = fightService.getFightByRoleId(pkRole.getRoleId());
        if (fightA != null) {
            RespMsg respMsg = new RespMsg();
            respMsg.setMsg("你在战斗中，无法切磋。");
            MessagePusher.pushMessage(session, respMsg);
            return;
        } else if (fightB != null) {
            RespMsg respMsg = new RespMsg();
            respMsg.setMsg("对方在战斗中，无法切磋。");
            MessagePusher.pushMessage(session, respMsg);
            return;
        }

        Map<String, Integer> setMap = role.getExtendBox().getSetMap();
        Map<String, Integer> pkSetMap = pkRole.getExtendBox().getSetMap();
        if (setMap.getOrDefault("refuse_fight", 0) == 1) {
            RespMsg respMsg = new RespMsg();
            respMsg.setMsg("你的切磋开关没有打开。");
            MessagePusher.pushMessage(session, respMsg);
            return;
        } else if (pkSetMap.getOrDefault("refuse_fight", 0) == 1) {
            RespMsg respMsg = new RespMsg();
            respMsg.setMsg("对方的切磋开关没有打开。");
            MessagePusher.pushMessage(session, respMsg);
            return;
        }
        /**
         * 走到这里说明可以创建战场进入战斗
         */
//        TeamService teamService = SpringUtils.getBean(TeamService.class);
//        Team team = teamService.getTeam(role.getRoleId());// 取己方队伍状态
//        Team pkTeam = teamService.getTeam(pkRole.getRoleId());// 取敌方队伍状态

        if (role.getPos().getMapId() == 38004) {
            return;
        }
        if (pkRole.getPos().getMapId() == 38004) {
            return;
        }

        if (team != null && pkTeam != null) {// 都组队
            if (team.getId() == pkTeam.getId()) {
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("同一队伍内成员无法切磋。"));
                return;
            }
            fightService.enterTeamPK(team.getList(), pkTeam.getList(), role);
        } else if (team != null) {// 对方没有组队 己方组队
            ArrayList<Member> arrayList = new ArrayList<>();
            Member member = Member.valueOf(pkRole);
            arrayList.add(member);
            fightService.enterTeamPK(team.getList(), arrayList, role);
        } else if (pkTeam != null) {// 对方组队 己方没有组队
            ArrayList<Member> arrayList = new ArrayList<>();
            Member member = Member.valueOf(role);
            arrayList.add(member);
            fightService.enterTeamPK(arrayList, pkTeam.getList(), role);
        } else {// 都没有组队
            ArrayList<Member> arrayListA = new ArrayList<>();
            Member memberA = Member.valueOf(role);
            arrayListA.add(memberA);

            ArrayList<Member> arrayListB = new ArrayList<>();
            Member memberB = Member.valueOf(pkRole);
            arrayListB.add(memberB);
            fightService.enterTeamPK(arrayListA, arrayListB, role);
        }
    }

    @RequestMapping
    public void changePosition(IoSession session, ReqMultiMoveTo reqMultiMoveTo) {
        try {
            movePosition(session, reqMultiMoveTo);
        } catch (Exception e) {
//            logger.warn("移动出错=={}", Lang.getStackTrace(e));
        }
    }

    /**
     * 移动位置
     *
     * @param session
     * @param reqMultiMoveTo
     */
    private void movePosition(IoSession session, ReqMultiMoveTo reqMultiMoveTo) {
        //logger.info("reqMultiMoveTo={}", JSONObject.toJSONString(reqMultiMoveTo));
        Role role = SessionUtils.getRoleBySession(session);
        if (role == null) {
            return;
        }
        /**战斗中，移动无效*/
        if (SpringUtils.getFightService().isInFight(role)) {
            return;
        }

        {
            {
                Object object = session.getAttribute("yidongyidongyidongyidongyidongyidongyidongyidongyidong");
                if (object == null) {
                    object = new ArrayList<Long>();
                    session.setAttribute("yidongyidongyidongyidongyidongyidongyidongyidongyidong",object);
                }
                ArrayList<Long> arrayList = (ArrayList<Long>) object;
                try {
//                    arrayList.add(System.currentTimeMillis());
//                    logger.error("==={}",Json.toJson(arrayList));
//                    if (arrayList.size() >= 10){
//                        session.setAttribute("yidongyidongyidongyidongyidongyidongyidongyidongyidong",new ArrayList<Long>());
//                        if (arrayList.get(1) - arrayList.get(0) <= 900
//                                && arrayList.get(2) - arrayList.get(1) <= 900
//                                && arrayList.get(3) - arrayList.get(2) <= 900
//                                && arrayList.get(4) - arrayList.get(3) <= 900
//                                && arrayList.get(5) - arrayList.get(4) <= 900
//                                && arrayList.get(6) - arrayList.get(5) <= 900
//                                && arrayList.get(7) - arrayList.get(6) <= 900
//                                && arrayList.get(8) - arrayList.get(7) <= 900
//                                && arrayList.get(9) - arrayList.get(8) <= 900){
//                            logger.error("移动检测到加速器=={}",role.getName());
//                            MessagePusher.pushMessage(session, new RespNotifyMiscEx("#R服务器认为你开了加速软件,3秒后将强制下线!!!"));
//                            MessagePusher.pushMessage(session, new RespNotifyMiscEx("#R服务器认为你开了加速软件,3秒后将强制下线!!!"));
//                            MessagePusher.pushMessage(session, new RespNotifyMiscEx("#R服务器认为你开了加速软件,3秒后将强制下线!!!"));
//                            MessagePusher.pushMessage(session, new RespNotifyMiscEx("#R服务器认为你开了加速软件,3秒后将强制下线!!!"));
//                            MessagePusher.pushMessage(session, new RespNotifyMiscEx("#R服务器认为你开了加速软件,3秒后将强制下线!!!"));
//                            MessagePusher.pushMessage(session, new RespNotifyMiscEx("#R服务器认为你开了加速软件,3秒后将强制下线!!!"));
////                            SpringUtils.getBean(PkService.class).add2Prison(role);
//                            ScheduledFuture<?> timeOutTask = SchedulerManager.getInstance().schedule(new Runnable() {
//                                @Override
//                                public void run() {
//                                    logger.error("移动加速器断开连接=={}",role.getName());
//                                    session.closeNow();
//                                }
//                            }, 3000);
//                            return;
//                        }
//                    }
                }catch (Exception e){
                   // logger.error("移动包出错==={}==={}",Json.toJson(arrayList),e);
                   // logger.error("移动包出错==角色名称={}==roleId={}",role.getName(),role.getRoleId());
                }
            }
        }
        /**两次移动包最小间隔时间1秒*/
        long now = System.currentTimeMillis();
        if (now - role.getPrevMoveTime() < 1000) {
            return;
        }
        role.setPrevMoveTime(now);

        SpringUtils.getRoleService().recordPosition(role, reqMultiMoveTo);
//        List<Position> list = reqMultiMoveTo.getList();
//        Position position = list.get(list.size() - 1);// 最后一个位置
//        role.setPos(position.getX(), position.getY(), reqMultiMoveTo.getDir(), reqMultiMoveTo.getMapId());
//        /** 产生一个移动事件，这个貌似会很频繁 */
        EventDispatcher.getInstance().fireEvent(new MoveEvent(EventType.MOVE, role));

//       initPos(reqMultiMoveTo.getMapId(),reqMultiMoveTo.getList());

    }

    /**
     * Todo 抓地图坐标点的方法 勿删
     */
    private void initPos(int mapId, List<Position> positions) {
        MapBossPos mapBossPos = SpringUtils.getBean(Dao.class).fetch(MapBossPos.class, Cnd.where("mapId", "=", mapId));
        if (mapBossPos == null) {
            mapBossPos = new MapBossPos();
            mapBossPos.setMapId(mapId);
            mapBossPos.setList(new ArrayList<>());
            SpringUtils.getBean(Dao.class).insert(mapBossPos);
        }
        for (Position position : positions) {
            mapBossPos.getList().add(position);
        }
        SpringUtils.getBean(Dao.class).updateIgnoreNull(mapBossPos);
    }

    /**
     * 捕捉
     *
     * @param session
     * @param reqCatchPet
     */
    @RequestMapping
    public void catchPet(IoSession session, ReqCatchPet reqCatchPet) {
        int monsterId = reqCatchPet.getMonsterId();
        Role role = SessionUtils.getRoleBySession(session);
        ReqFightDoAction ReqFightDoAction = new ReqFightDoAction();
        ReqFightDoAction.setTargetId(monsterId);
        ReqFightDoAction.setAttackerId(role.getRoleId());
        ReqFightDoAction.setType(FightAction.CATCH_PET);
        Fight fight = fightService.getFightByRoleId(role.getRoleId());
        if (fight != null) {
            boolean canCatch = true;
            FightObject target = fight.queryFightObject(monsterId);
            if (target == null) {
                canCatch = false;
            } else {
                PetObject pet = PetDataPool.getPetObject(target.getName());
                if (pet == null) {
                    canCatch = false;
                }else{
                    int hostId = target.getHostId();
                    //查找主人ID
                    Role hostRole = SpringUtils.getRoleService().getPlayerBy(hostId);
                    if(hostRole != null){
                        canCatch = false;
                    }else {
                        if (pet.getPetType() != PetType.NORMAL) {
                            canCatch = false;
                        }
                    }
                }
            }
            if (!canCatch) {
                RespMsg respMsg = new RespMsg();
                respMsg.setMsg("目标无法被捕捉。");
                RespSyncMessage respSyncMessage = new RespSyncMessage();
                respSyncMessage.setCode((short) 8165);
                respSyncMessage.setMsg(AsktaoUtil.getMessageBody(respMsg));
                MessagePusher.pushMessage(session, respSyncMessage);

                RespCombatCommandAccepted respCombatCommandAccepted = new RespCombatCommandAccepted();
                respCombatCommandAccepted.setId(role.getRoleId());
                MessagePusher.pushMessage(session, respCombatCommandAccepted);
            } else {
                fightExecutorService.addFightTask(fight, () -> fightService.doAction(ReqFightDoAction));
            }

        }
    }

    /**
     * 逃跑
     *
     * @param session
     * @param ReqFightFlee
     */
    @RequestMapping
    public void runaway(IoSession session, ReqFightFlee ReqFightFlee) {// 逃跑需要判断

        Role role = SessionUtils.getRoleBySession(session);
        ReqFightDoAction reqFightDoAction = new ReqFightDoAction();
        reqFightDoAction.setType(FightAction.FLEE);
        reqFightDoAction.setAttackerId(role.getRoleId());
        reqFightDoAction.setTargetId(role.getRoleId());

        if (SpringUtils.getMapService().isInMap(role, 38004)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("当前地图不允许逃跑！"));
            return;
        }
        if (SpringUtils.getMapService().isInMap(role, 60006)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("当前地图不允许逃跑！"));
            return;
        }
        Fight fight = fightService.getFightByRoleId(role.getRoleId());
        if (fight != null) {
            fightExecutorService.addFightTask(fight, () -> fightService.doAction(reqFightDoAction));
        }
    }

    /**
     * 战斗手动出手
     */
    @RequestMapping
    public void fightAction(IoSession session, ReqFightDoAction ReqFightDoAction) {
        Role role = SessionUtils.getRoleBySession(session);
        if (role == null) {
            return;
        }

        Fight fight = fightService.getFightByRoleId(role.getRoleId());
        if (fight == null) {
            return;
        }
        if (!fightService.canProcessSkill(role, fight, ReqFightDoAction.getSkillId())) {
            return;
        }

        fightExecutorService.addFightTask(fight, () -> {
            try {
                if (ReqFightDoAction.getType() == 1 || ReqFightDoAction.getType() == 2
                        || ReqFightDoAction.getType() == 3 || ReqFightDoAction.getType() == 16) {
                    FightObject fightObject = fight.queryFightObject(ReqFightDoAction.getAttackerId());
                    if (fightObject != null) {
                        fightObject.setAutoFightType(ReqFightDoAction.getType());
                        fightObject.setAutoSkillId(ReqFightDoAction.getSkillId());
                        fightObject.setAutoTarget(ReqFightDoAction.getTargetId());
                        fightObject.setTargetId(ReqFightDoAction.getTargetId());
                    }
                    /**
                     * 记录出手方式和技能 置自动出手 只在战斗类型1 2 3的时候给客户端发
                     */
                    RespFightCommandInfo respFightCommandInfo = new RespFightCommandInfo();
                    respFightCommandInfo.setId(ReqFightDoAction.getAttackerId());
                    respFightCommandInfo.setType((short) ReqFightDoAction.getType());
                    respFightCommandInfo.setSkillId(ReqFightDoAction.getSkillId());
                    MessagePusher.pushMessage(session, respFightCommandInfo);
                }
                for (FightObject memberObject : fight.getAllFightObjects()) {
                    if (memberObject.isPlayer()) {
                        if (!SpringUtils.getRoleService().isOnline(memberObject.getRole().getId())) {
                            memberObject.setAutoFight((byte) 1);
                            fightService.autoFightOne(fight, memberObject);
                        }
                    }

                }
                SpringUtils.getFightService().doAction(ReqFightDoAction);
            } catch (Exception e) {
             //   logger.error("手动出手出错==={}", Lang.getStackTrace(e));
                ReqFightDoAction.setType(1);
                ReqFightDoAction.setTargetId(ReqFightDoAction.getAttackerId());
                ReqFightDoAction.setSkillId(0);
                SpringUtils.getFightService().doAction(ReqFightDoAction);
            }
        });
    }

    /**
     * 请求下一回合?
     */
    @RequestMapping
    public void nextRound(IoSession session, ReqCombatEndAnimate ReqCombatEndAnimate) {
        log.error("请求面板=={}=answer={}", ReqCombatEndAnimate.getAnswer());
        Role role = SessionUtils.getRoleBySession(session);
        if (role == null) {
            return;
        }
        Fight fight = fightService.getFightByRoleId(role.getRoleId());
        if (fight == null) {
            return;
        }
        log.error("请求面板=={}=answer={}", role.getName(), ReqCombatEndAnimate.getAnswer());
        /**这里要判断当前回合是否已经请求过面板 否则发封包可以无限跳回合*/
        fightExecutorService.addFightTask(fight, () -> fightService.nextRound(role, fight));
        //假人不会发送下回合面板。补偿假人包。
        //判断当前人队伍中是否有假人。
        if(SpringUtils.getBean(TeamService.class).isInTeam(role)){
            //当前是是否是队长
            if(SpringUtils.getBean(TeamService.class).isTeamLeader(role)){
                //队长发送下回合面板，连带队伍假人一起发送。
                Team team = SpringUtils.getBean(TeamService.class).getTeam(role.getRoleId());
                ArrayList<Member> list = team.getList();
                for (Member member : list) {
                    Role aiRole = SpringUtils.getRoleService().getOnlinePlayer(member.getRoleId());
                    if(aiRole.getAitype() > 0){
                        //是假人
                        fightExecutorService.addFightTask(fight, () -> fightService.nextRound(aiRole, fight));
                    }
                }
            }
        }
    }

    /**
     * 打开战斗喊话
     */
    @RequestMapping
    public void openFightMsg(IoSession session, ReqOpenFightMsgDlg reqOpenFightMsgDlg) {
        Role role = SessionUtils.getRoleBySession(session);
        String content = null;
        if (reqOpenFightMsgDlg.getId() == role.getRoleId()) {// 设置人物喊话
            content = Json.toJson(role.getShouts());
        } else {// 设置宠物喊话
            Pet pet = SpringUtils.getPetService().getPetById(reqOpenFightMsgDlg.getId(), role);
            if (pet != null) {
                content = Json.toJson(pet.getShouts());
            }
        }
        if (Strings.isEmpty(content) || content.equals("null")) {
            content = "[]";
        }
        RespFightMsgDlg respFightMsgDlg = new RespFightMsgDlg();
        respFightMsgDlg.setId(reqOpenFightMsgDlg.getId());
        respFightMsgDlg.setMsg(content);
        MessagePusher.pushMessage(session, respFightMsgDlg);
    }

    /**
     * 设置战斗喊话
     */
    @RequestMapping
    public void setFightMsg(IoSession session, ReqSetFightMsg reqSetFightMsg) {
        Role role = SessionUtils.getRoleBySession(session);
        List<NutMap> list = Json.fromJsonAsList(NutMap.class, reqSetFightMsg.getMsg());
        for (NutMap nutMap : list) {
            nutMap.remove("op_type");
        }
        if (reqSetFightMsg.getId() == role.getRoleId()) {// 设置人物喊话
            role.setShouts(list);
            role.save();
        } else {// 设置宠物喊话
            Pet pet = SpringUtils.getPetService().getPetById(reqSetFightMsg.getId(), role);
            if (pet != null) {
                pet.setShouts(list);
                role.save();
            }
        }
        RespFightMsgDlg respFightMsgDlg = new RespFightMsgDlg();
        respFightMsgDlg.setId(reqSetFightMsg.getId());
        respFightMsgDlg.setMsg(Json.toJson(list));
        MessagePusher.pushMessage(session, respFightMsgDlg);
    }

    /**
     * 处理登出事件
     */
    @EventHandler(EventType.LOGOUT)
    public void handleLogoutEvent(LogoutEvent LogoutEvent) {
        Role role = LogoutEvent.getRole();
        Fight fight = fightService.getFightByRoleId(role.getRoleId());
        if (fight == null) {
            return;
        }
        fightExecutorService.addFightTask(fight, () -> {
            FightObject fightObject = fight.queryFightObject(role.getRoleId());
            if (fightObject != null) {
                if (fight.isOver()) {
                    for (FightObject temp : fight.getAllFightObjects()) {
                        fightService.quiteFight(fight, temp, false);
                    }
                    fightService.clearFight(fight);
                } else {
                    FightMessageUtil.sendFightPackage(fight, SpringUtils.getFightMessageService().charOffline(role.getRoleId(), 1));
                    fightObject.setAutoFight((byte) 1);
                    fightService.autoFightOne(fight, fightObject);
                    for (FightObject memberObject : fight.getAllFightObjects()) {
                        if (memberObject.isPlayer()) {
                            IoSession ioSession = memberObject.getSession();
                            if (ioSession == null) {
                                memberObject.setAutoFight((byte) 1);
                                fightService.autoFightOne(fight, memberObject);
                            }
                        }
                    }
                }
            }
        });
    }

    @RequestMapping
    public void setAutoVictim(IoSession session, ReqAutoFightSetVictim setVictim) {

    }
}
